import 'package:business_plugin/business/config_business/business_config_model.dart';
import 'package:business_plugin/business/config_business/config_business.dart';
import 'package:business_plugin/business/firebase_helper.dart';
import 'package:business_plugin/utils/business_tools.dart';

class UserManager {
  static final UserManager _instance = UserManager._internal();

  factory UserManager() {
    return _instance;
  }

  UserManager._internal();

  void initBusinessConfig() {
    final config = BusinessConfigModel(
      apiKey: "AIzaSyAJIoUdgcmt1rsOztrZ-bFq16esaabOUX8",
      appId: "1:660093983547:ios:a7fa0281f5095ba45ff51e",
      messagingSenderId: "660093983547",
      projectId: "clearify-1c1e4",
      storageBucket: "clearify-1c1e4.firebasestorage.app",
      iosBundleId: "com.clearify.ai.storge.cleaner.photo.compress.merge",
      flyOpenId: '',
      bannerAdId: '',
      rewardedAdId: 'ca-app-pub-3916046151571724/8689334147',
      releaseAdvertisement: true,
      tdAppId: "",
      tdServerUrl: "https://ss.zolnm.com/",
      adjustIsDebug: false,
      adjustId: "",
      adjustLogLevel: BusinessConfigModel.parseAdjustLogLevel("verbose"),
    );
    // 初始化配置
    ConfigBusiness.initialize(config);
    ConfigBusiness.adjustCallback = (bool isPromoteUser) {};
  }

  //firebase服务
  Future<void> initServices() async {
    await initFirebaseHelper();
  }

  Future<void> initFirebaseHelper() async {
    try {
      await FirebaseHelper.init();
      BusinessTools.log('FirebaseHelper 初始化完成');
    } catch (e) {
      BusinessTools.log('FirebaseHelper 初始化失败: $e');
      //重新初始化
      await initFirebaseHelper();
    }
  }
}
